package com.example.service.impl;

import com.example.domain.dto.DepartmentDTO;
import com.example.domain.po.Department;
import com.example.mapper.DepartmentMapper;
import com.example.mapper.HospitalDepartmentMapper;
import com.example.service.HospitalDepartmentService;
import com.example.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Service
public class HospitalDepartmentServiceImpl implements HospitalDepartmentService {

    @Autowired
    HospitalDepartmentMapper hospitalDepartmentMapper;

    @Autowired
    DepartmentMapper departmentMapper;

    @Override
    public void add(DepartmentDTO departmentDTO) {
        hospitalDepartmentMapper.add(departmentDTO);

    }

    @Override
    public void update(DepartmentDTO departmentDTO) {
        hospitalDepartmentMapper.update(departmentDTO);
    }

    @Override
    public Result<List<Department>> findAdd(Integer hospitalId) {
        //查全部部门
        List<Department> allList = departmentMapper.list();

        //查询该医院已有的部门
        List<Department> haveList = departmentMapper.findByHospitalId(hospitalId);

        List<Department> result = allList.stream()
                .filter(element -> !haveList.contains(element))
                .collect(Collectors.toList());

        return Result.success(result);
    }

    @Override
    public void del(Integer hospitalId, Integer departmentId) {
        hospitalDepartmentMapper.del(hospitalId,departmentId);
    }
}
